package com.xawx.hch.finances.activity;

import com.xawx.hch.finances.util.ExitApplication;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

/**
 * Title: LoginActivity
 * Description: 
 * Copyright: Copyright (c) 2012
 * Company: Xawx Teachnology
 * CreateTime: Apr 28, 2012 10:40:36 AM
 * 
 * @author hch
 * @version %A%, %B%
 * @since JDK1.6
 */
public class MainActivity extends TabActivity {
	public TabHost tabHost;
	public static final String TAB_HOME = "首页";
	public static final String TAB_MSG = "�ڶ���";
	public static final String TAB_THREE = "�����";
	public static final String TAB_FORE = "���ĸ�";
	public RadioGroup radioGroup;
	final int LIST_DIALOG = 0;
	private Builder b;
	public SQLiteDatabase db;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		ExitApplication.getInstance().addActivity(this);
		tabHost = MainActivity.this.getTabHost();
		Intent intent = getIntent();
		String badge = intent.getStringExtra("badge");
		if ("搜索".equals(badge)) {
			tabHost.setCurrentTabByTag(TAB_MSG);
			TabSpec ts2 = tabHost
					.newTabSpec(TAB_MSG)
					.setIndicator(TAB_MSG)
					.setContent(
							new Intent(MainActivity.this, SouSuoActivity.class));
			tabHost.addTab(ts2);
		}
		if ("首页".equals(badge)) {
			tabHost.setCurrentTabByTag(TAB_HOME);
			tabHost.setCurrentTabByTag(TAB_MSG);
			TabSpec ts1 = tabHost
					.newTabSpec(TAB_HOME)
					.setIndicator(TAB_HOME)
					.setContent(
							new Intent(MainActivity.this, ShouYeActivity.class));
			tabHost.addTab(ts1);
		}
		if ("设置".equals(badge)) {
			tabHost.setCurrentTabByTag(TAB_THREE);
			TabSpec ts3 = tabHost
					.newTabSpec(TAB_THREE)
					.setIndicator(TAB_THREE)
					.setContent(
							new Intent(MainActivity.this,
									SetXiTongActivity.class));
			tabHost.addTab(ts3);
		}
		TabSpec ts1 = tabHost
				.newTabSpec(TAB_HOME)
				.setIndicator(TAB_HOME)
				.setContent(new Intent(MainActivity.this, ShouYeActivity.class));
		tabHost.addTab(ts1);
		TabSpec ts2 = tabHost
				.newTabSpec(TAB_MSG)
				.setIndicator(TAB_MSG)
				.setContent(new Intent(MainActivity.this, SouSuoActivity.class));
		tabHost.addTab(ts2);
		TabSpec ts3 = tabHost
				.newTabSpec(TAB_THREE)
				.setIndicator(TAB_THREE)
				.setContent(
						new Intent(MainActivity.this, SetXiTongActivity.class));
		tabHost.addTab(ts3);
		this.radioGroup = (RadioGroup) findViewById(R.id.main_radio);
		radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
				case R.id.radio_button0:
					tabHost.setCurrentTabByTag(TAB_HOME);
					break;
				case R.id.radio_button1:
					tabHost.setCurrentTabByTag(TAB_MSG);
					break;
				case R.id.radio_button2:
					tabHost.setCurrentTabByTag(TAB_THREE);
					Log.d("select ID", "===={" + checkedId + "}");
					break;
				case R.id.radio_button3:
					showDialog(LIST_DIALOG);
					break;
				}
			}
		});

	}
	protected Dialog onCreateDialog(int id, Bundle args) {
		switch (id) {
		case LIST_DIALOG: 
			b = new AlertDialog.Builder(MainActivity.this);
			b.setTitle("ȷ���˳�ϵͳ��");
			b.setPositiveButton("ȷ��", new OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					ExitApplication.getInstance().exit();
				}
			});
			b.setNegativeButton("ȡ��", new OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
				}
			});
			return b.create();
		}
		return null;
	}
}